﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;

namespace BLL.RunReport
{
    public class ReportManager
    {
        OracleDAL.RunReport.ReportManager r = new OracleDAL.RunReport.ReportManager();
        public string getStatisticItem(string id)
        {
            string itemStr = getStatisticItemCon(id);
            string contentTable = string.Empty;
            int count = 1;//跨行数
            DataSet ds = new DataSet();
            ds = getStatisticItem();
            if (ds.Tables[0] != null)
            {
                if (ds.Tables[0].Rows.Count > 0)
                {
                    for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                    {
                        if (i % 5 == 0)//大于5种类型换行
                        {
                            count++;
                            if (itemStr.IndexOf(ds.Tables[0].Rows[i]["itemid"].ToString ()) != -1)
                            {
                                contentTable += "</tr><tr><td><input type=\"checkbox\" checked=\"true\" db=\"" + ds.Tables[0].Rows[i]["databasekind"] + "\"  proc=\"" + ds.Tables[0].Rows[i]["matchprocname"] + "\" value =\"" + ds.Tables[0].Rows[i]["itemname"] + "\" id =\"" + ds.Tables[0].Rows[i]["itemid"] + "\" /> " + ds.Tables[0].Rows[i]["itemname"] + "</td>";
                            }
                            else 
                            {
                                contentTable += "</tr><tr><td><input type=\"checkbox\" db=\"" + ds.Tables[0].Rows[i]["databasekind"] + "\"  proc=\"" + ds.Tables[0].Rows[i]["matchprocname"] + "\" value =\"" + ds.Tables[0].Rows[i]["itemname"] + "\" id =\"" + ds.Tables[0].Rows[i]["itemid"] + "\" /> " + ds.Tables[0].Rows[i]["itemname"] + "</td>";
                            }


                        }
                        else
                        {
                            if (itemStr.IndexOf(ds.Tables[0].Rows[i]["itemid"].ToString ()) != -1)
                            {
                                contentTable += "<td><input type=\"checkbox\" checked=\"true\" db=\"" + ds.Tables[0].Rows[i]["databasekind"] + "\"  proc=\"" + ds.Tables[0].Rows[i]["matchprocname"] + "\"  value =\"" + ds.Tables[0].Rows[i]["itemname"] + "\" id =\"" + ds.Tables[0].Rows[i]["itemid"] + "\" /> " + ds.Tables[0].Rows[i]["itemname"] + "</td>";
                            }
                            else
                            {
                                contentTable += "<td><input type=\"checkbox\" db=\"" + ds.Tables[0].Rows[i]["databasekind"] + "\"  proc=\"" + ds.Tables[0].Rows[i]["matchprocname"] + "\"  value =\"" + ds.Tables[0].Rows[i]["itemname"] + "\" id =\"" + ds.Tables[0].Rows[i]["itemid"] + "\" /> " + ds.Tables[0].Rows[i]["itemname"] + "</td>";
                            }
                           
                        }
                    }
                }
            }
            if (contentTable != "")
            {
                contentTable = "<table id=\"tbStContent\" cellpadding=\"0\" width =\"100%\" cellspacing=\"0\" ><tr>" + contentTable + "</tr></table>";//生成TABLE表格及其单元格事件
            }

            ds.Clear();
            ds.Dispose();
            return contentTable;
        }
        /// <summary>
        /// 掉用存储过程插入运行详细表
        /// </summary>
        /// <param name="procID"></param>
        /// <param name="starttime"></param>
        /// <param name="endtime"></param>
        /// <param name="statisticid"></param>
        /// <returns></returns>
        public string setDateReport(string procID, string starttime, string endtime, string statisticid)
        {
            DataSet ds = new DataSet();  //获取配置
            string[] arrpid = procID.Split(',');
            for (int i = 0; i < arrpid.Length; i++)
            {

            }
            return "0";
        }
        public string getStatisticItemCon(string id)
        {
            return r.getStatisticItem(id);
        }
        public string getStatisticItemConMy(string id)
        {
            return r.getStatisticItemConMy(id);
        }
        
        /// <summary>
        /// 
        /// </summary>
        /// <param name="sql"></param>
        /// <returns></returns>
        public int excutSql(string sql)
        {
            return r.excutSql(sql);
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="strWhere"></param>
        /// <returns></returns>
        public DataSet getStatistic(string strWhere)
        {
            return r.getStatistic(strWhere);
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="id"></param>
        public void delReport(string id)
        {
            r.delReport(id);
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public DataSet getStatisticDetail(string id)
        {
            return r.getStatisticDetail(id);
        }
        public DataSet getConfigAll()
        {
         
            return r.getConfigAll();
        }
        public DataSet getStatisticItem()
        {
            return r.getStatisticItem();
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="statisticID"></param>
        /// <param name="itemIdCon">itemid 和 数据库类型</param>
        /// <param name="starttime"></param>
        /// <param name="endtime"></param>
        /// <returns></returns>
        public int excutProc(string statisticID, string itemIdCon, string starttime, string endtime)
        {
            r.excutProc(statisticID, itemIdCon, starttime, endtime);
            return 1;
        }
        /// <summary>
        /// 获取默认开始时间
        /// </summary>
        public DataSet  getdefaultStartTime()
        {
            return r.getdefaultStartTime();
        }
    }
}
